package com.hapzxb.thread.synchronizede;


/**
 * Synchronized锁对象介绍 1.对于普通同步方法，锁是当前对象 2.对于静态同步方法，锁的当前类的class对象 3.对于同步代码块，锁是Synchronized括号里的对象
 *
 * @Author: zhaoxb
 * @Date: 2019-04-04 14:14
 **/
public class SynchronizedDemo1 {

    public synchronized void synMethodA() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(50L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread name;" + Thread.currentThread().getName() + " ,synMethodA....");
        }
    }

    public synchronized void synMethodB() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(50L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread name;" + Thread.currentThread().getName() + " ,synMethodB....");
        }
    }

    public static synchronized void staticSynMethodA() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(50L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread name;" + Thread.currentThread().getName() + " ,staticSynMethodA....");
        }
    }

    public static synchronized void staticSynMethodB() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(50L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread name;" + Thread.currentThread().getName() + " ,staticSynMethodB....");
        }
    }


}
